package com.arrays;

public class RemoveElement0123_27 {
    public int removeElement(int[] nums, int val) {
        int index = nums.length-1;
        for (int i = 0; i <= index; i++) {
            if(nums[i] == val){
                while (index>=i){
                    if(nums[index] != val){
                        nums[i] = nums[index];
                        index--;
                        break;
                    }
                    index--;
                }
            }
        }
        return index+1;
    }
}
